// /**
//  * Created by Mr.Xing on 2018/10/18.
//  */
//

mini.parse();
//控件属性 联动
function tableType(){

    var typeId = mini.get("typeId");//数据来源
    var dataSources = mini.get("dataSources");//参照来源
    var dataType = mini.get("dataType");//参照类型
    var tdNum1 = mini.get("tdNum1");
    var int = typeId.getValue();
    var cz = dataType.getValue();
    console.log(cz);
    // console.log(bootPATH,'bootPATH');

    if (int == 1){

    }else if (int == 2){

        var url = bootPATH + "../frame/frame1/data/DataSourse1.txt";

        dataSources.setUrl(url);
        dataType.setUrl(url);
    }else if (int == 3){

        dbSource();
        var url = bootPATH + "../frame/frame1/data/DataSourse2.txt";
        dataType.setUrl(url);

    }else if (int == 4){

        var url = bootPATH + "../frame/frame1/data/DataSourse3.txt";
        dataType.setUrl(url);

    }else if (int == 5){
        var id = click_ids[click_ids.length -1];
        // var properties = properties;
        mini.open({
            url : bootPATH + "../frame/frame1/pages/formLayout/foreignSource.html",
            title : "外部数据源链接属性",
            onload: function () {       //弹出页面加载完成
                var iframe = this.getIFrameEl();
                var data = { action: "edit-db", id: id, properties: properties };
                iframe.contentWindow.SetDbData(data);
            },
            ondestroy: function (action) {  //弹出页面关闭前
                if (action == "ok") {       //如果点击“确定”
                    var iframe = this.getIFrameEl();
                    var data = iframe.contentWindow.onDBData();
                    data = mini.clone(data);
                    console.log(data);
                    console.log(click_ids[click_ids.length-1],'当前组件id');
                    console.log(click_type,'当前组件类型');

                    var thisID = click_ids[click_ids.length-1];
                    if(click_type == 'form'){
                        var proper = properties_form;
                    }else if(click_type == 'table'){
                        var proper = properties_table;
                    }
                    for(var i=0;i<proper.length;i++) {
                        if(proper[i].cTableField == thisID) {
                            proper[i].dbSourse = data;
                        }
                    }
                    console.log(proper,'增加外部数据');
                }
            }
        })
    }

}
//验证数据来源，为系统档案时，显示数据库表名。
function dbSource(){

    var url = ajaxUrl + "/tableClass/list.do";
    $.ajax({
        type : 'GET',
        url : url,
        dataType : 'json',
        success : function (data){
            var dbSource = mini.get("dataSources");
            var d = data.data;
            var dbData = [];
            for(var i = 0; i<d.length; i++){
                dbData[i] = {
                    "id": i, "text": d[i].tableChClassName,
                }
            }
            dbSource.setData(dbData);
        },
        error : function (message){
            mini.alert("获取数据源错误");
        }

    })
}

//参照弹窗
function cz() {
    //类型是参照
    var dataType = mini.get("dataType");//参照类型
    var cz = dataType.getValue();
    var id = click_ids[click_ids.length -1];
    if(cz == 'buttonedit') {
        mini.open({
            url: bootPATH + "../frame/frame1/pages/formLayout/dataType.html",
            title: "参照",
            onload: function () {
                // var iframe = this.getIFrameEl();
                // var data = {
                //      id: id
                // };
                // iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {//关闭之前执行
                if (action == "ok") {
                    var iframe = this.getIFrameEl();
                    var data = iframe.contentWindow.onTableOk();
                    data = mini.clone(data);
                    console.log(data,'选择的参照');
                    // console.log(click_type,'当前组件类型');
                    var thisID = click_ids[click_ids.length-1];
                    console.log(thisID,'当前组件id');

                    for(var i=0;i<properties.length;i++) {
                        if(properties[i].cTableField == thisID) {
                            properties[i].reference = data[0];
                        }
                    }
                    console.log(properties,'增加参照数据成功');
                }
            }
        })
    }
}